﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace cinetoona
{
    public partial class CreateShow : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            using (DataAccessDataContext cinetoonadb = new DataAccessDataContext())
            {
                //var joinShowMovies = (from m in cinetoonadb.Movies
                //                     join s in cinetoonadb.Shows on m.MovieID equals s.MovieID
                //                     select new { Title = s.Movies.Title }).Distinct();

                var getTheater = from t in cinetoonadb.Theaters
                                select new {t.TheaterID, t.Name};

                TheaterDropDownList.DataSource = getTheater;
                TheaterDropDownList.DataTextField = "Name";
                TheaterDropDownList.DataValueField = "TheaterID";
                TheaterDropDownList.DataBind();

                var getMovies = from m in cinetoonadb.Movies
                                select new { m.Title, m.MovieID };

                MovieDropDownList.DataSource = getMovies;
                MovieDropDownList.DataTextField = "Title";
                MovieDropDownList.DataValueField = "MovieID";
                MovieDropDownList.DataBind();

                MovieDropDownList1.DataSource = getMovies;
                MovieDropDownList1.DataTextField = "Title";
                MovieDropDownList1.DataValueField = "MovieID";
                MovieDropDownList1.DataBind();

            }
        }

        
        protected void CreateShowButton_Click(object sender, EventArgs e)
        {
            using (DataAccessDataContext cinetoonadb = new DataAccessDataContext())
            {
                Show show = new Show();
                show.TheaterID = Convert.ToInt32(TheaterDropDownList.SelectedValue);
                show.MovieID = Convert.ToInt32(MovieDropDownList.SelectedValue);
                show.Tickets = Convert.ToInt32(ThicketTextBox.Text);
                show.Start = Convert.ToDateTime(StartTimeTextBox.Text);

                cinetoonadb.Shows.InsertOnSubmit(show);
                cinetoonadb.SubmitChanges();
            }  
        }




    }
}